package com.xykj.service.impl;

import com.xykj.mapper.NewStockCalendarMapper;
import com.xykj.pojo.dto.NewStockCalendarDto;
import com.xykj.service.NewStockCalendarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.List;

/**
 * @ClassDescription: 新股上市日历service实现类
 * @author:yzh
 * @create:2025/5/12 20:32
 **/
@Service
public class NewStockCalendarServiceImpl implements NewStockCalendarService {

    @Autowired
    private NewStockCalendarMapper newStockCalendarMapper;

    @Override
    public List<NewStockCalendarDto> queryNewStockCalendar(Integer pageNum, Integer pageSize) {
        //得到本周的周一和周末日期
        LocalDate today = LocalDate.now();
        LocalDate monday = today.with(DayOfWeek.MONDAY);
        LocalDate sunday = today.with(DayOfWeek.SUNDAY);
        int offset = (pageNum - 1) * pageSize;
        //分页查询并返回
         return newStockCalendarMapper.selectRecentWeek(monday, sunday, offset, pageSize);
    }

    @Override
    public Integer totalNewStockCalendar() {
        return newStockCalendarMapper.queryRecentWeekCount();
    }
}
